// JavaScript Document
//@require Class.js

IndicadorGeneral = new MyClass({
	/**  
     * Property: alimentacion
	 * 	 Estado de la alimentacion (conectada/desconectada)
     * {boolean} - false:cerrada, null|NaN:no especifica
     */
	alimentacion: null, 
	/**  
     * Property: baliza
	 * 	 Estado de la baliza, encendida/apagada 
     * {boolean} - false:cerrada, null|NaN:no especifica
     */
	baliza: null,
	/**  
     * Property: aceite
	 * 	 Estado del aceite.
     * {boolean} - false:cerrada, null|NaN:no especifica
     */
	aceite: null,
	/**  
     * Property: imagesURL
     * {String}
     */
	imagesURL: 'js/tablero/images/', 
	/** 
     * Property: display
     * {DOMElement} 
     */
	display: null, 
	/** 
     * SIZE of DISPLAY
     */
	width: '120px',
	height: '30px',
	/** 
     * Property: puerta1div
     * {DOMElement: div} 
     */
	alimentaciondiv: null,
	balizadiv: null,
	aceitediv: null,

	init: function(imagesURL){
		if (imagesURL!=null)
			this.imagesURL = imagesURL;
		this.display = document.createElement("div");
		with (this.display.style){
			width = this.width;
			height = this.height;
			background = "transparent url("+this.imagesURL+"indicadorGeneral.gif) no-repeat center";	
		}
		
		this.alimentaciondiv = document.createElement("div");
		with (this.alimentaciondiv.style){
			width = this.width;
			height = this.height;		
			background = "transparent";
		}
		this.display.appendChild(this.alimentaciondiv);	
		
		this.aceitediv = document.createElement("div");
		with (this.aceitediv.style){
			width = this.width;
			height = this.height;
			background = "transparent";
		}
		this.alimentaciondiv.appendChild(this.aceitediv);
		
		this.balizadiv = document.createElement("div");
		with (this.balizadiv.style){
			width = this.width;
			height = this.height;
			background = "transparent";
		}
		this.aceitediv.appendChild(this.balizadiv);		
	},
	
	/** 
     * Method: putDisplayIn
     *  
     * Parameters:
     * idElement - {String} 
     */
	putDisplayIn: function(idElement){
		document.getElementById(idElement).appendChild(this.display);
	},
	
	/** 
     * Method: setValues
     *  Setea el estado de los leds
     * Parameters:
     * 	alimentacion, p2, p3, p4, p5 - {Boolean} 
     */
	setValues: function(alimentacion, aceite, baliza) {
	
		if (this.alimentacion!=alimentacion){
			this.alimentacion = alimentacion;
			if ((this.alimentacion==null)||(isNaN(this.alimentacion)))
				this.alimentaciondiv.style.background = "transparent";
			else		
				if (this.alimentacion)
					this.alimentaciondiv.style.background = "transparent url("+this.imagesURL+"alimentacionGreen.gif) no-repeat";
				else
					this.alimentaciondiv.style.background = "transparent url("+this.imagesURL+"alimentacionRed.gif) no-repeat";
		}
		
		if (this.aceite!=aceite){
			this.aceite=aceite;
			if ((this.aceite==null)||(isNaN(this.aceite)))
				this.aceitediv.style.background = "transparent";
			else		
				if (this.aceite)
					this.aceitediv.style.background = "transparent url("+this.imagesURL+"aceiteGreen.gif) no-repeat";
				else
					this.aceitediv.style.background = "transparent url("+this.imagesURL+"aceiteRed.gif) no-repeat";
		}
		
		if (this.baliza!=baliza){
			this.baliza=baliza;
			if ((this.baliza==null)||(isNaN(this.baliza)))
				this.balizadiv.style.background = "transparent";
			else		
				if (this.baliza)
					this.balizadiv.style.background = "transparent url("+this.imagesURL+"balizaGreen.gif) no-repeat";
				else
					this.balizadiv.style.background = "transparent url("+this.imagesURL+"balizaRed.gif) no-repeat";
		}
		
		this.generateTooltip();
	},
	
	/** 
     * Method: generateTooltip
	 *   Formatea e inserta el tooltip (title) al componente actual
     * Parameters:
     * 	toValue - {Integer} 
     */
	generateTooltip: function(){
		var texto = 'ALIMENTACION: ';
		if ((this.alimentacion==null)||(isNaN(this.alimentacion)))
			texto += 'desconocido';			
		else if(this.alimentacion)
				texto += 'Conectada';
			 else
			 	texto += 'Desconectada';
		
		texto += '\n ACEITE: ';
		if ((this.aceite==null)||(isNaN(this.aceite)))
			texto += 'desconocido';			
		else if(this.aceite)
				texto += 'OK';
			 else
			 	texto += 'Mal!';
		
		texto += '\n BALIZAS: ';
		if ((this.baliza==null)||(isNaN(this.baliza)))
			texto += 'desconocido';			
		else if(this.aceite)
				texto += 'Encendidas';
			 else
			 	texto += 'Apagadas';

		this.display.title = texto;
	}
	
});